package com.yeyks.common.em.vip;

import com.yeyks.common.exception.ServiceException;

import java.util.Objects;

public enum VipCardTypeEnum {

    VIP(1),
    JIP(2);

    private Integer value;

    VipCardTypeEnum(Integer value) {
        this.value = value;
    }

    public Integer getValue() {
        return value;
    }

    //根据订单类型获取会员卡类型
    public static Integer getCardTypeByOrderVipFlagValue(Integer value) {
        switch (value) {
            case 1:
                return VipCardTypeEnum.VIP.getValue();
            case 3:
                return VipCardTypeEnum.JIP.getValue();
            default:
                return 0;
        }
    }

    public static Integer getCardTypeByOrderVipFlagValueThrowE(Integer value) {
        Integer cardType = getCardTypeByOrderVipFlagValue(value);
        if (Objects.equals(cardType, 0)) {
            throw new ServiceException("订单类型获取会员卡类型失败");
        }
        return cardType;
    }

    //根据会员卡充值类型获取会员卡类型
    public static Integer getCardTypeByRechargeRecordTypeValue(Integer value) {
        switch (value) {
            case 2:
                return VipCardTypeEnum.VIP.getValue();
            case 4:
                return VipCardTypeEnum.JIP.getValue();
            default:
                return 0;
        }
    }

    public static Integer getCardTypeByRechargeRecordTypeValueThrowE(Integer value) {
        Integer cardType = getCardTypeByRechargeRecordTypeValue(value);
        if (Objects.equals(cardType, 0)) {
            throw new ServiceException("订单类型获取会员卡类型失败");
        }
        return cardType;
    }

}
